﻿<template>
  <div class="card-fill layout-padding">
    <el-card shadow="hover" class="layout-padding-auto">
      <div>
        <el-form ref="formRefProductionLine" :model="stateProductionLine.vmModel" label-width="100px">
          <el-row>
            <el-col :xs="24" :lg="24" class="mb20">
              <el-form-item ref="Entity_Name_FormItem" prop="Entity.Name"
                :label="$t('message.autotrans._Model_ProductionLine_Name')"
                :rules="[{ required: true, message: $t('message._system.common.vm.input', { input: $t('message.autotrans._Model_ProductionLine_Name') }), trigger: 'blur' }]">
                <el-input v-model="stateProductionLine.vmModel.Entity.Name" clearable></el-input>
              </el-form-item>

            </el-col>
            <el-col :xs="24" :lg="24" class="mb20">
              <el-form-item ref="Entity_Code_FormItem" prop="Entity.Code"
                :label="$t('message.autotrans._Model_ProductionLine_Code')"
                :rules="[{ required: true, message: $t('message._system.common.vm.input', { input: $t('message.autotrans._Model_ProductionLine_Code') }), trigger: 'blur' }]">
                <el-input v-model="stateProductionLine.vmModel.Entity.Code" clearable></el-input>
              </el-form-item>

            </el-col>

            <!-- <el-col :xs="24" :lg="24" class="mb20">
              <el-form-item ref="Entity_ProductId_FormItem" prop="Entity.ProductId" :rules="[
                {
                  required: true,
                  message: $t('message._system.common.vm.input', { input: $t('message.autotrans._Model_ProcessRoute_ProductId') }),
                  trigger: 'blur',
                },
              ]" :label="$t('message.autotrans._Model_ProcessRoute_ProductId')">
                <el-select v-model="stateProductionLine.vmModel.Entity.ProductId" clearable>
                  <el-option v-for="item in stateProductionLine.AllProducts" :key="item.Value" :value="item.Value"
                    :label="item.Text"></el-option>
                </el-select>
              </el-form-item>
            </el-col> -->

            <!--        <el-col :xs="24" :lg="24" class="mb20">-->
            <!--        <el-form-item ref="Entity_ProductName_FormItem" prop="Entity.ProductName" :label="$t('message.autotrans._Model_ProductionLine_ProductName')">-->
            <!--            <el-input v-model="stateProductionLine.vmModel.Entity.ProductName" clearable></el-input>-->
            <!--        </el-form-item>-->

            <!--        </el-col>-->
            <el-col :xs="24" :lg="24" class="mb20">
              <el-form-item ref="Entity_PrincipalIdId_FormItem" prop="Entity.PrincipalIdId"
                :label="$t('message.autotrans._Model_ProductionLine_PrincipalId')">
                <el-select v-model="stateProductionLine.vmModel.Entity.PrincipalIdId" clearable>
                  <el-option v-for="item in stateProductionLine.AllPrincipalIds" :key="item.Value" :value="item.Value"
                    :label="item.Text"></el-option>
                </el-select>
              </el-form-item>

            </el-col>
            <el-col :xs="24" :lg="24" class="mb20">
              <el-form-item ref="Entity_Active_FormItem" prop="Entity.Active"
                :label="$t('message.autotrans._Model_ProductionLine_Active')">
                <el-select v-model="stateProductionLine.vmModel.Entity.Active" clearable>
                  <el-option :key="1" :value=true :label="$t('message._system.common.vm.tips_bool_true')"></el-option>
                  <el-option :key="0" :value=false :label="$t('message._system.common.vm.tips_bool_false')"></el-option>
                </el-select>
              </el-form-item>

            </el-col>
          </el-row>
          <el-tabs type="border-card">
            <el-tab-pane :label="$t('message.autotrans._Model_ProcessRouteItem_EquipmentId')" key="关联设备">

              <el-col :xs="24" :lg="24" class="mb20">

                <el-form-item ref="SelectedEquipmentProductionLine_MT_WtmsIDs_FormItem"
                  prop="SelectedEquipmentProductionLines"
                  :label="$t('message.autotrans._Model_ProcessRouteItem_EquipmentId')">
                  <el-transfer filterable v-model="stateProductionLine.vmModel.SelectedEquipmentProductionLines"
                    :data="stateProductionLine.AllEquipmentProductionLine_MT_Wtms" clearable>
                    <template #left-empty>
                      <el-empty :image-size="60" description="No data" />
                    </template>
                    <template #right-empty>
                      <el-empty :image-size="60" description="No data" />
                    </template>
                  </el-transfer>
                </el-form-item>

              </el-col>
            </el-tab-pane>
            <el-tab-pane :label="$t('message.autotrans._Model_ProductionLine_Product')" key="生产产品">

              <el-col :xs="24" :lg="24" class="mb20">
                <el-form-item ref="SelectedProductProductionLine_MT_WtmsIDs_FormItem"
                  prop="SelectedProductProductionLines" :label="$t('message.autotrans._Model_ProductionLine_Product')">
                  <el-transfer filterable v-model="stateProductionLine.vmModel.SelectedProductProductionLines"
                    :data="stateProductionLine.AllProductProductionLine_MT_Wtms" clearable>
                    <template #left-empty>
                      <el-empty :image-size="60" description="No data" />
                    </template>
                    <template #right-empty>
                      <el-empty :image-size="60" description="No data" />
                    </template>
                  </el-transfer>
                </el-form-item>

              </el-col>
            </el-tab-pane>
            <el-tab-pane :label="$t('message.autotrans._Model_LineShift_Name')" key="生产班次">
              <WtmTable ref="tableRefLineShiftLineList1" v-bind="tableDataLineShiftLineList1"
                v-model="stateProductionLine.vmModel.Entity.LineShift_Line"></WtmTable>
            </el-tab-pane>
          </el-tabs>
          <!-- <WtmTable ref="tableRefLineShiftLineList1" v-bind="tableDataLineShiftLineList1"
            v-model="stateProductionLine.vmModel.Entity.LineShift_Line"></WtmTable> -->
          <div style="text-align:right;">
            <WtmButton @click="onSubmitProductionLine" type="primary" :button-text="$t('message.autotrans.SysSubmit')"
              style="margin-top:15px;" />

            <WtmButton @click="onCloseProductionLine" type="primary" :button-text="$t('message.autotrans.SysClose')"
              style="margin-top:15px;" />

          </div>

        </el-form>

      </div>

    </el-card>
  </div>
</template>


<script setup lang="ts" name="message.autotrans._PageFactoryManagementProductionLineEdit;false">
import { ElMessageBox, ElMessage, ElLoading } from 'element-plus';
import { defineAsyncComponent, reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { productionlineApi } from '/@/api/factorymanagement/productionline';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const tableRefLineShiftLineList1 = ref();
const tableDataLineShiftLineList1 = ref({
  // 列表数据（必传）
  data: [],
  // 表头内容（必传，注意格式）
  header: [
    { title: ci.proxy.$t('message.autotrans.Page班次'), key: 'Name', type: 'textbox', isCheck: true },
    { title: ci.proxy.$t('message.autotrans.Page班次编码'), key: 'Code', type: 'textbox', sortable: 'custom', isCheck: true },
    { title: ci.proxy.$t('message.autotrans.Page开始时间'), key: 'StartTime', type: 'time', isCheck: true },
    { title: ci.proxy.$t('message.autotrans.Page结束时间'), key: 'EndTime', type: 'time', isCheck: true },
    { title: ci.proxy.$t('message.autotrans._AdminDuration'), key: 'Hours', type: 'textbox', isCheck: true },
    {
      title: ci.proxy.$t('message.autotrans.Page跨天'), key: 'CrossDays', type: 'switch', defaultValue: false, comboData:
      {
        true: ci.proxy.$t('message._system.common.vm.tips_bool_true'),
        false: ci.proxy.$t('message._system.common.vm.tips_bool_false')
      }, isCheck: true
    },

  ],
  // 配置项（必传）
  config: {
    total: 0, // 列表总数
    loading: false, // loading 加载
    isSerialNo: true, // 是否显示表格序号
    isSelection: true, // 是否显示表格多选
    isOperate: true, // 是否显示表格操作栏
    isSub: true,
    isDisabled: false
  }
});

// 定义变量内容
const formRefProductionLine = ref();
const stateProductionLine = reactive({
  vmModel: {
    Entity: {
      Name: '',
      Code: '',
      ProductName: '',
      ProductId: undefined,
      PrincipalIdId: null,
      Active: undefined,
      LineShift_Line: [],
      ID: null,
    },

    SelectedEquipmentProductionLines: [],
    SelectedProductProductionLines: [],
    OldSelectedEquipmentProductionLines: [],
    OldSelectedProductProductionLines: [],
  },
  AllProducts: [] as any[],
  AllPrincipalIds: [] as any[],
  AllLines: [] as any[],
  AllEquipmentProductionLine_MT_Wtms: [] as any[],
  AllProductProductionLine_MT_Wtms: [] as any[],
});

// 取消
const onCloseProductionLine = () => {
  closeDialog();
};

// 提交
const onSubmitProductionLine = () => {
  const loadingInstance = ElLoading.service({
    lock: true,
    text: '正在提交中，请等待。。。',
    background: 'rgba(0, 0, 0, 0.7)',
  });
  formRefProductionLine.value?.validate((valid: boolean, fields: any) => {
    if (valid) {
      productionlineApi().edit(stateProductionLine.vmModel).then(() => {
        ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
        emit('refresh');
        closeDialog();
      }).catch((error) => {
        other.setFormError(ci, error);
      }).finally(() => {
        loadingInstance.close();
      })
    }
    else {
      loadingInstance.close();
    }
  })
};

// 页面加载时
onMounted(() => {
  other.getSelectList('/api/FactoryManagement/ProductionLine/GetEquipments', [], false).then(x => { stateProductionLine.AllEquipmentProductionLine_MT_Wtms = other.setlectToTransfer(x) });
  other.getSelectList('/api/FactoryManagement/ProductionLine/GetProducts', [], false).then(x => { stateProductionLine.AllProductProductionLine_MT_Wtms = other.setlectToTransfer(x) });
  other.getSelectList('/api/ProductManagement/ProductBom/GetProducts', [], false).then(x => { stateProductionLine.AllProducts = x });
  other.getSelectList('/api/FactoryManagement/ProductionLine/GetFrameworkUsers', [], false).then(x => { stateProductionLine.AllPrincipalIds = x });
  other.getSelectList('/api/FactoryManagement/LineShift/GetProductionLines', [], false).then(x => { stateProductionLine.AllLines = x });
  if (ci.attrs["wtmdata"]) {
    stateProductionLine.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
  }
  else if (useRouter().currentRoute.value.query.id) {
    stateProductionLine.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
  }
  productionlineApi().get(stateProductionLine.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateProductionLine.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh', 'closeDialog']);
// 关闭弹窗
const closeDialog = () => {
  emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss"></style>
